<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Permission
{
	public $permissions = array(
								"create"=>false,
								"delete"=>false,
								"edit"=>false,
								"special"=>false,
								"admin"=>false
							);

	public function setPermissions($permissions=array())
	{
		foreach($this->permissions as $key => $value)
		{
			$this->permissions[$key]=(isset($permissions[$key])&& $permissions[$key])?true:false;
		}
		return $this->permissions;
	}

	public function getPermissions($bitMask =0)
	{
		$i = 0;
		foreach($this->permissions as $key => $value)
		{
			$this->permissions[$key]=(($bitMask & pow(2, $i))!=0)? true: false;
			$i++;
		}
		return $this->permissions;
	}
	public function getPermissionKeys()
	{
		return array_keys($this->permissions);
	}
	function toBitmask()
	{
		$bitmask = 0;
		$i = 0;
		foreach($this->permissions as $key => $value)
		{
			if($value)
			{
				$bitmask += pow(2, $i);
			}
			$i++;
		}
		return $bitmask;
	}
}







